package com.abbas.CayTcore.ui

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.abbas.CayTcore.R
import com.abbas.CayTcore.adapter.InfoAdapter
import com.abbas.CayTcore.adapter.NowProductAdapter
import com.abbas.CayTcore.base.BaseFragment
import com.abbas.CayTcore.databinding.FragmentWindingUplevelBinding
import com.abbas.CayTcore.entity.vo.InfoVO
import com.abbas.CayTcore.entity.vo.ScheduleVO
import com.abbas.CayTcore.presenter.WindingHomeUplevelPresenter
import com.abbas.CayTcore.view.ViewContract

class WindingHomeViewModel() : ViewModel() {

    val infoList: MutableLiveData<MutableList<InfoVO>> = MutableLiveData<MutableList<InfoVO>>(
        mutableListOf()
    )
    val nowProductList: MutableLiveData<MutableList<ScheduleVO>> = MutableLiveData<MutableList<ScheduleVO>>(
        mutableListOf()
    )





}

/**
 * 绕线主页
 */
class WindingHomeUplevelFragment :
    BaseFragment<ViewContract.WindingHomeUplevelView, WindingHomeUplevelPresenter, FragmentWindingUplevelBinding>(),
    ViewContract.WindingHomeUplevelView {

    override fun getViewBinding(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): FragmentWindingUplevelBinding {
        return FragmentWindingUplevelBinding.inflate(inflater, container, false)
    }

    override fun initPresenter(): WindingHomeUplevelPresenter {
        return WindingHomeUplevelPresenter()
    }

    override fun initData() {
        presenter.run {
            getInfo()
            getSchedule()
        }
    }

    override fun initEvent() {
        binding.seeAll.setOnClickListener {
            findNavController().navigate(R.id.windingAllDataUpFragment)
        }
    }

    /**
     * @time 23/05/03 15:57
     * bug: 不显示内容
     *
     * @time now 04
     * 太久没写，居然搞忘了布局管理器
     */
    override fun onInfoGetten(adapter: InfoAdapter) {
        binding.warmingRv.apply {
            layoutManager = LinearLayoutManager(requireContext()).apply {
                orientation = LinearLayoutManager.VERTICAL
            }
            this.adapter = adapter
        }
    }

    override fun onScheduleGetten(productAdapter: NowProductAdapter) {
        binding.nowRv.apply {
            layoutManager = LinearLayoutManager(requireContext()).apply {
                orientation = LinearLayoutManager.VERTICAL
            }
            this.adapter = productAdapter
        }
    }
}